package kz.pompei.OneGwt.client.personrole.impl;

import kz.pompei.OneGwt.client.personrole.PersonroleManagerMed;
import kz.pompei.OneGwt.remote.PersonroleManagerServiceAsync;

import com.google.gwt.user.client.ui.Widget;

public class PersonroleManagerBuilder {
  
  //Исходные данные строительства
  private PersonroleManagerServiceAsync service;
  
  //Результаты строительства
  private PersonroleManagerMed mediator;
  private Widget containerUI;
  
  public void build() {
    PersonroleManagerMedImpl mainMed = new PersonroleManagerMedImpl();
    final PersonroleManagerViewImpl mainView = new PersonroleManagerViewImpl();
    mainMed.setView( mainView );
    mainMed.setService( service );
    
    {
      PersonListMedImpl m1 = new PersonListMedImpl();
      PersonListViewImpl v1 = new PersonListViewImpl();
      
      m1.setView( v1 );
      m1.setService( service );
      
      mainMed.setPersonListMed( m1 );
      
      mainView.setPersonListContainerUI( v1.getContainerUI() );
      
      {
        PersonFormMedImpl m2 = new PersonFormMedImpl();
        PersonFormViewImpl v2 = new PersonFormViewImpl();
        m2.setView( v2 );
        m2.setService( service );
        
        m1.setPersonFormMed( m2 );
        
        v2.getRelativeObjectTranspazon().setSource( v1.getPersonListSource() );
      }
      {
        RoleListMedImpl m3 = new RoleListMedImpl();
        RoleListViewImpl v3 = new RoleListViewImpl();
        
        m3.setView( v3 );
        m3.setService( service );
        
        mainMed.setRoleListMed( m3 );
        mainView.setRoleListContainerUI( v3.getContainerUI() );
      }
    }
    
    mediator = mainMed;
    containerUI = mainView.getContainerUI();
  }
  
  public void setService(PersonroleManagerServiceAsync service) {
    this.service = service;
  }
  
  public PersonroleManagerMed getMediator() {
    return mediator;
  }
  
  public Widget getContainerUI() {
    return containerUI;
  }
}
